﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BLL;
using System.Collections.Generic;
using Entities;

namespace RailwayReservationSystem.Client
{
    public partial class FindTrain : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void LoadData(int StationFrom, int StationTo, String date, int CoachTypeID)
        {
            ScheduleBUS sdBus = new ScheduleBUS();
            List<Schedule> td = ScheduleBUS.SearchSchedule(StationFrom, StationTo, date, CoachTypeID);
            List<Station> ListStation = StationBUS.GetStation();
            List<CoachType> ListCoachType = CoachTypeBUS.GetCoachType();

            ddlTo.DataSource = ddlFrom.DataSource = ListStation;
            ddlCoachType.DataSource = ListCoachType;

            ddlFrom.DataBind();
            ddlTo.DataBind();
            ddlCoachType.DataBind();

            gvSchedule.DataSource = td;
            gvSchedule.DataBind();
            lbQuantiy.Text = td.Count.ToString();
            HeaderRounte.InnerHtml = StationBUS.Get_Station_ByID(StationFrom).StastionName + " – " + StationBUS.Get_Station_ByID(StationTo).StastionName + @"<span style='margin-left:30px;'>Travel Date: " + date + " </span>";

            ddlFrom.SelectedValue = StationFrom.ToString();
            ddlTo.SelectedValue = StationTo.ToString();
            ddlCoachType.SelectedValue = CoachTypeID.ToString();
        }

        protected void ddlFrom_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["StationFrom"] = ddlFrom.SelectedValue;
            int StationFrom = Int32.Parse(Session["StationFrom"].ToString());
            int StationTo = Int32.Parse(Session["StationTo"].ToString());
            int CoachTypeID = Int32.Parse(Session["CoachTypeID"].ToString());
            String Date = Session["Date"].ToString();
            LoadData(StationFrom, StationTo, Date, CoachTypeID);
            TB_window.Style.Add("display", "none");
        }

        protected void ddlTo_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["StationTo"] = ddlTo.SelectedValue;
            int StationFrom = Int32.Parse(Session["StationFrom"].ToString());
            int StationTo = Int32.Parse(Session["StationTo"].ToString());
            int CoachTypeID = Int32.Parse(Session["CoachTypeID"].ToString());
            String Date = Session["Date"].ToString();
            LoadData(StationFrom, StationTo, Date, CoachTypeID);
            TB_window.Style.Add("display", "none");
        }

        protected void ddlCoachType_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["CoachTypeID"] = ddlCoachType.SelectedValue;
            int StationFrom = Int32.Parse(Session["StationFrom"].ToString());
            int StationTo = Int32.Parse(Session["StationTo"].ToString());
            int CoachTypeID = Int32.Parse(Session["CoachTypeID"].ToString());
            String Date = Session["Date"].ToString();
            LoadData(StationFrom, StationTo, Date, CoachTypeID);
            TB_window.Style.Add("display", "none");
        }
    }
}